import net.protocol.MsgArg;
import net.protocol.NetMsgArg;
import net.protocol.NetMsgCenter;
import protocol.HelloWorld;
import net.NetClient;
import net.buffer.IntPack;

import java.io.IOException;

public class Application {
    public static void main(String[] args) throws InterruptedException, IOException {

        NetClient client = new NetClient("127.0.0.1", 54321, new IntPack(126),2000);
        NetMsgCenter.getInstance().register(client);
        NetMsgCenter.getInstance().addMsgListener(HelloWorld.class, Application::recv);
        client.start();
        int count = 5;
        while(count-->0)
        {
            HelloWorld hl = new HelloWorld();
            hl.setHi("This is a simple msg!");
            NetMsgArg arg = new NetMsgArg();
            arg.content(hl);
            arg.client(client);
            NetMsgCenter.getInstance().sendAsync(arg);
            Thread.sleep(500);
        }
    }

    public static void recv(MsgArg data)
    {
//        System.out.println("recv!");
       HelloWorld helloWorld = data.content();
       System.out.println(helloWorld);
    }
}
